<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Convert a string to a certain case
 * @access public
 * @param string $str String to be converted
 * @param string $case Case from which the string will be converted from
 * @return string Return converted string
 */
function changeCase($str, $case = 'readable')
{
    switch($case)
    {
        case 'human' :
            $str_space      = preg_replace('/(\w+)([A-Z])/U', '\\1 \\2', $str);
            $str_dash       = str_replace('-', ' ', $str_space);
            $str_readable   = str_replace('_', ' ', $str_dash);
            return $str_readable;
            break;
        case 'human_lower' :
            $str_space      = preg_replace('/(\w+)([A-Z])/U', '\\1 \\2', $str);
            $str_dash       = str_replace('-', ' ', $str_space);
            $str_readable   = str_replace('_', ' ', $str_dash);
            return strtolower($str_readable);
            break;
        case 'human_upper' :
            $str_space      = preg_replace('/(\w+)([A-Z])/U', '\\1 \\2', $str);
            $str_dash       = str_replace('-', ' ', $str_space);
            $str_readable   = str_replace('_', ' ', $str_dash);
            return ucwords($str_readable);
            break;
        case 'snake' :
            $str_space      = preg_replace('/(\w+)([A-Z])/U', '\\1_\\2', $str);
            $snake_dash     = str_replace('-', '_', $str_space);
            $string_lower   = strtolower($snake_dash);
            $str_snake      = str_replace(' ', '_', $string_lower);
            return $str_snake;
            break;
        case 'dash' :
            $str_space      = preg_replace('/(\w+)([A-Z])/U', '\\1_\\2', $str);
            $dash_dash      = str_replace('_', '-', $str_space);
            $string_lower   = strtolower($dash_dash);
            $str_dash       = str_replace(' ', '-', $string_lower);
            return $str_dash;
            break;
        case 'camel' :
            $str_dash       = str_replace('-', ' ', $str);
            $str_space      = str_replace('_', ' ', $str_dash);
            $str_upper      = ucwords($str_space);
            $str_no_space   = str_replace(' ', '', $str_upper);
            $str_camel      = lcfirst($str_no_space);
            return $str_camel;
            break;
        case 'pascal' :
            $str_dash       = str_replace('-', ' ', $str);
            $str_space      = str_replace('_', ' ', $str_dash);
            $str_upper      = ucwords($str_space);
            $str_pascal     = str_replace(' ', '', $str_upper);
            return $str_pascal;
            break;
        default :
            $str_space      = preg_replace('/(\w+)([A-Z])/U', '\\1_\\2', $str);
            $snake_dash     = str_replace('-', '_', $str_space);
            $string_lower   = strtolower($snake_dash);
            $str_snake      = str_replace(' ', '_', $string_lower);
            return $str_snake;
            break;
    }
}

/* End of file api_helper.php */
/* Location: ./application/helpers/api_helper.php */